package com.shf.mapper;

import com.shf.entity.Users;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/***
 *
 * 用户持久层
 */
public interface UserMapper {

    @Select("select *from user where username = #{username}")
    @Results(id="usersMapper",value = {
            @Result(property = "roles",javaType = List.class,column = "id",many = @Many(select = "com.shf.mapper.RoleMapper.findRolesByUserid"))
    })
    Users findUser(String username);

    /**
     * 添加用户
     * @param users
     * @return
     */
    @Insert("insert into user values (#{id},#{username},#{password},#{email},#{phoneNum},#{status})")
    int saveUser(Users users);

    /**
     * 展示所有用户
     * @return
     */
    @Select("select * from user")
    List<Users> UserFindAll();

    /**
     * 展示详情
     * @param id
     * @return
     */
    Users userDetail(Integer id);

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("select  id,username from user where id = #{id}")
    Users findUserById(Integer id);

    /**
     *
     * 删除用户
     * @param id
     */
    @Delete("delete from user where id =#{id}")
    void deleteUser(String id);
}
